package com.xiaobawang.xjsyy_idea_plugin.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author synhard
 * @description TODO
 * @date 2024/6/5 17:42
 * @email songxinhang2023@e-chinalife.com
 * @id 18101119
 * @phone 13001321080
 */
public class DateUtil {
    private static final String dateFormat = "yyyy-MM-dd HH:mm:ss";

    public static String parseTimestampToDateStr(Long timestamp) {
        Date             date          = new Date(timestamp);
        SimpleDateFormat sdf           = new SimpleDateFormat(dateFormat);
        return sdf.format(date);
    }

    public static String formatTimeDifference(long timestamp1, long timestamp2) {
        long difference = Math.abs(timestamp1 - timestamp2);
        long seconds = difference / 1000 % 60;
        long minutes = difference / (1000 * 60) % 60;
        long hours = difference / (1000 * 60 * 60);

        if (hours > 0) {
            return String.format("%d小时%d分钟%d秒", hours, minutes, seconds);
        } else if (minutes > 0) {
            return String.format("%d分钟%d秒", minutes, seconds);
        } else {
            return String.format("%d秒", seconds);
        }
    }
}
